//退出点击功能
const logout = document.querySelector(".logout");
logout.addEventListener("click", function (e) {
  if (confirm("确定要退出吗？")) {
    localStorage.removeItem("cms1");
    location.href = "./login.html";
  }
});
//给一级标题绑定点击事件
const topMenList = document.querySelectorAll(".nav>li>a");
topMenList.forEach((toA) => {
  //addEventListener  捕获 冒泡事件
  toA.addEventListener("click", function (e) {
    //nextElementSibling  子节点
    $(this.nextElementSibling).slideToggle();
  });
});
//二级标题点击高亮
const SubTitle = document.querySelectorAll(".nav ul a");
SubTitle.forEach((SubA) => {
  SubA.addEventListener("click", function (e) {
    const be = document.querySelector(".nav ul li a.active");
    console.log(be);
    be.classList.remove("active");
    console.log(SubA);
    this.classList.add("active");
  });
});
//初始化用户数据
const initBut = document.querySelector(".init");
initBut.addEventListener("click", async function (e) {
  //请求数据
  const result = await axios({
    url: "/init/data",
    headers: {
      Authorization: localStorage.getItem("cms1"),
    },
  });
  console.log(result);
  if (result.data.code === 0) {
    toastr.success(result.data.message);
  }
});
